package com.yzt.zhuju.event;

import rx.Subscription;

/**
 * author : bob
 * date   : 2022/11/29
 * desc   :
 */
public class SubscriptionWrapper implements Subscription {

    private Subscription subscription;

    private final SubscriptionDelegate delegate;

    public SubscriptionWrapper(Subscription actual, SubscriptionDelegate delegate) {
        this.subscription = actual;
        this.delegate = delegate;
    }

    @Override
    public void unsubscribe() {
        if (subscription != null) {
            subscription.unsubscribe();
        }
        if (delegate != null) {
            delegate.onUnsubscribe();
        }
    }

    @Override
    public boolean isUnsubscribed() {
        if (subscription != null) {
            return subscription.isUnsubscribed();
        }
        return false;
    }

    public void updateActual(Subscription actual) {
        this.subscription = actual;
    }

    interface SubscriptionDelegate {
        /**
         * 接触注解
         */
        void onUnsubscribe();
    }
}
